package com.buddy.sds.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.buddy.sds.auth.entity.SystemDictItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ISystemDictItemMapper extends BaseMapper<SystemDictItem> {

    @Delete("delete from t_system_dict_item where item_dict = #{dict}")
    void deleteByDict(String dictDict);

    @Select("select exists(select item_key from t_system_dict_item where item_key = #{key})")
    boolean existsByKey(String key);

    @Select("select item_id,item_name,item_key,item_dict from t_system_dict_item left join t_system_dict on dict_id = item_dict where item_key = #{item_key} and dict_ident = #{dict_ident}")
    SystemDictItem getByIdentAndKey(@Param("dict_ident") String dictIdent, @Param("item_key") String itemKey);

    @Select("select item_id,item_name,item_key,item_dict from t_system_dict left join t_system_dict_item on dict_id = item_dict where dict_ident=#{ident}")
    List<SystemDictItem> getByDictIdent(String dictIdent);
}
